//
//外协退货单
//
<template>
  <div class="tenantMenu_main main_container">
    <div class="main_header">
      <div class="padding_container">
        <div class="left"><Breadcrumb /></div>
        <div class="right">
          <HeaderOperation :parent="this" />
        </div>
      </div>
    </div>
    <div v-loading="loading" class="main_main">
      <SearchBar :parent="this" />
      <div ref="table_container" class="table_container">
        <el-table
          v-if="tableColumns.length>0"
          ref="table"
          :data="tableData"
          stripe
          border
          :height="tableHeight"
          style="width: 99.9%"
          row-key="id"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          :cell-style="cellStyle"
          @cell-click="cellClick"
          @sort-change="(column)=>{sortChange(column, this)}"
          @selection-change="(val)=>{selectionChange(val, this)}"
        >
          <el-table-column type="selection" width="70" align="center" />
          <Column v-for="(column,index) in tableColumns" :key="index" :prop="column.prop" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" />
          <el-table-column label="操作" align="center" fixed="right" width="180">
            <template slot-scope="scope">
              <el-button
                v-hasPermi="['outsource:returnGoods:edit']"
                type="text"
                @click.stop="edit(scope.row)"
              >编辑</el-button>
              <el-button
                v-hasPermi="['outsource:returnGoods:remove']"
                type="text"
                @click.stop="deleteOne(scope.row)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>
    <PrintEquipmentInfo ref="print" :print-data="printData" />
  </div>
</template>

<script>
import { list, remove, getInfo } from '@/api/outsourceManage/outsourceReturn'
import AddOrUpdate from './addOrUpdate'
import AddOrUpdateRoam from './addOrUpdateRoam.vue'
import ShowDetail from '../../purchaseManage/purchaseReturn/showPurchaseReturn' // 查看页面
export default {
  name: 'Index',
  // components: { PrintEquipmentInfo }, // 组件注册
  data() {
    return {
      loading: true,
      pageId: '外协退货单', // 页面唯一标识
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc'
      },
      typeData: {
        status: 1
      },
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'code', label: '退货单号' },
        { prop: 'returnByName', label: '退货人员', canOrder: false },
        { prop: 'returnTime', label: '退货日期' },
        { prop: 'badnessCode', label: '不良品处置单' },
        { prop: 'outsourceSupplierName', label: '外协供应商', canOrder: false },
        { prop: 'outsourceOrderCode', label: '外协订单号' },
        { prop: 'reason', label: '退货原因', canOrder: false },
        { prop: 'remark', label: '备注', canOrder: false }
      ],
      defaultSearchColumns: [// 搜索区常规字段（初始值）
        { prop: 'code', label: '退货单号', type: 'input' },
        { prop: 'disqualificationCode', label: '不良品处置单', type: 'input' },
        { prop: 'returnByName', label: '退货人员', type: 'input' },
        { prop: 'outsourceOrderCode', label: '外协订单号', type: 'input' },
        { prop: 'reason', label: '退货原因', type: 'input' },
        { prop: 'returnTime', label: '退货日期', type: 'time' },
        { prop: 'outsourceSupplierName', label: '外协供应商', type: 'input' }
      ],
      operationData: [ // 右上角的操作按钮
        { label: '新增', perm: 'outsource:returnGoods:add' },
        { label: '批量操作', perm: '' },
        { label: '批量删除', perm: 'outsource:returnGoods:remove' },
        { label: '打印', perm: 'outsource:returnGoods:list' },
        // { label: '批量导出', perm: 'outsource:returnGoods:export' },
        { label: '页面配置', perm: '' }
      ],
      printData: [],
      showKey: [ // 查看详情的配置（根据配置自动生成查看页面）
      // 自动流转查看
        {
          name: '基本信息',
          columns: [
            { type: 'form', name: '退货单号', key: 'code' }, // type: 'form' 表示是普通的表单展示
            { type: 'form', name: '退货人员', key: 'returnByName' },
            { type: 'form', name: '退货日期', key: 'returnTime' },
            { type: 'form', name: '不良品处置单', key: 'qualityDisqualificationDisposeCode' },
            { type: 'form', name: '外协订单号', key: 'outsourceOrderCode' }, // length:'double' 表示占两列
            { type: 'form', name: '外协供应商', key: 'outsourceSupplierName' }, // type: 'form' 表示是普通的表单展示
            { type: 'file', name: '附件', fileName: 'fileName', fileRealName: 'fileRealName', fileUrl: 'url' },
            { type: 'form', name: '退货原因', key: 'reason', length: 'double' },
            { type: 'form', name: '备注', key: 'remark', length: 'double' },
            {
              type: 'table', name: '', key: 'detailList', columns: [ // type: 'table' 表示是表格
                { type: 'form', name: '物料编码', key: 'materialCode', minWidth: '120' }, // type: 'form' 表示是普通的表单展示
                { type: 'form', name: '物料名称', key: 'materialName', minWidth: '100' },
                { type: 'form', name: '规格型号', key: 'materialModel', minWidth: '100' },
                { type: 'form', name: '物料单位', key: 'materialUnitLabel', minWidth: '100' },
                { type: 'form', name: '外协数量', key: 'outsourceNumber', minWidth: this.SETTINGS.settings_decimalDigits_length }, // type: 'form' 表示是普通的表单展示
                { type: 'form', name: '不良数量', key: 'disqualificationNumber', minWidth: this.SETTINGS.settings_decimalDigits_length },
                { type: 'form', name: '退货数量', key: 'returnNumber', fixed: 'right', minWidth: this.SETTINGS.settings_decimalDigits_length },
                { type: 'form', name: '备注', key: 'remark', minWidth: '200' } // type: 'form' 表示是普通的表单展示
              ]
            }
          ]
        },
        {
          name: '供应商信息',
          columns: [
            { type: 'form', name: '交货方式', key: 'returnTypeName' }, // type: 'form' 表示是普通的表单展示
            { type: 'form', name: '收货人', key: 'consignee' },
            { type: 'form', name: '联系方式', key: 'contract' },
            { type: 'form', name: '注意事项', key: 'announcements' },
            { type: 'form', name: '收货地址', key: 'receiveAddress', length: 'double' }
          ]
        }
      ],
      showKey2: [ // 查看详情的配置（根据配置自动生成查看页面）
      // 新增查看
        {
          name: '基本信息',
          columns: [
            { type: 'form', name: '退货单号', key: 'code' }, // type: 'form' 表示是普通的表单展示
            { type: 'form', name: '退货人员', key: 'returnByName' },
            { type: 'form', name: '退货日期', key: 'returnTime' },
            { type: 'form', name: '不良品处置单', key: 'qualityProductDisqualificationDisposeCode' },
            { type: 'form', name: '外协订单号', key: 'outsourceOrderCode' }, // length:'double' 表示占两列
            { type: 'form', name: '外协供应商', key: 'outsourceSupplierName' }, // type: 'form' 表示是普通的表单展示
            { type: 'file', name: '附件', fileName: 'fileName', fileRealName: 'fileRealName', fileUrl: 'url' },
            { type: 'form', name: '退货原因', key: 'reason', length: 'double' },
            { type: 'form', name: '备注', key: 'remark', length: 'double' },
            {
              type: 'table', name: '', key: 'detailList', columns: [ // type: 'table' 表示是表格
                { type: 'form', name: '物料编码', key: 'materialCode', minWidth: '120' }, // type: 'form' 表示是普通的表单展示
                { type: 'form', name: '物料名称', key: 'materialName', minWidth: '100' },
                { type: 'form', name: '规格型号', key: 'materialModel', minWidth: '100' },
                { type: 'form', name: '物料单位', key: 'materialUnitLabel', minWidth: '100' },
                { type: 'form', name: '外协数量', key: 'outsourceNumber', minWidth: this.SETTINGS.settings_decimalDigits_length }, // type: 'form' 表示是普通的表单展示
                // { type: 'form', name: '不良数量', key: 'disqualificationNumber', minWidth: this.SETTINGS.settings_decimalDigits_length },
                { type: 'form', name: '备注', key: 'remark', minWidth: '200' }, // type: 'form' 表示是普通的表单展示
                { type: 'form', name: '退货数量', key: 'returnNumber', fixed: 'right', minWidth: this.SETTINGS.settings_decimalDigits_length }
              ]
            }
          ]
        },
        {
          name: '供应商信息',
          columns: [
            { type: 'form', name: '交货方式', key: 'returnTypeName' }, // type: 'form' 表示是普通的表单展示
            { type: 'form', name: '收货人', key: 'consignee' },
            { type: 'form', name: '联系方式', key: 'contract' },
            { type: 'form', name: '注意事项', key: 'announcements' },
            { type: 'form', name: '收货地址', key: 'receiveAddress', length: 'double' }
          ]
        }
      ]
    }
  },
  created() {
  },
  methods: {
    cellStyle({ row, column }) {
      if (column.property == 'code') {
        return {
          cursor: 'pointer',
          color: '#387bfc'
        }
      }
    },
    cellClick(row, column, cell) {
      switch (column.property) {
        case 'code':
          this.showDetail(row)
          break
      }
    },
    getList() {
      list(this.pageData).then(res => {
        this.tableData = res.data
        this.total = res.total
        this.$nextTick(() => {
          this.setSelectRow(this)// 设置行选中
          this.tableHeight = this.$refs.table_container.offsetHeight
        })
      })
    },
    getExportData(data) {
      return list(data)
    },
    refresh() {
      this.pageData.pageNum = 1
      this.getList()
    },
    showDetail(row) {
      console.log(row.automaticCreate)
      getInfo(row[this.mainId]).then(res => {
        this.$layer.iframe({// 弹框
          content: {
            content: ShowDetail, // 传递的组件对象
            parent: this, // 当前的vue对象
            data: {
              showData: res.data,
              showKey: row.automaticCreate == 1 ? this.showKey2 : this.showKey
            }// props
          },
          area: ['1320px', '700px'],
          title: '查看外协退货单', // 标题
          shadeClose: false // 点击遮罩是否关闭
        })
      })
    },
    add() {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {}// props
        },
        area: ['1320px', '700px'],
        title: '新增外协退货单', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    edit(row) {
      this.$layer.iframe({// 弹框
        content: {
          // content: row.automaticCreate == '1' ? AddOrUpdateRoam : AddOrUpdate, // 传递的组件对象
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
            id: row[this.mainId]
          }// props
        },
        area: ['1320px', '700px'],
        title: '编辑外协退货单', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    deleteOne(row) {
      const _this = this
      this.$confirm('确定要删除吗', '删除确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消', cancelButtonClass: 'cancelConfirm',
        type: 'warning'
      }).then(function() {
        remove(row[_this.mainId]).then(res => {
          _this.$message({
            message: res.msg,
            type: 'success'
          })
          _this.getList()
        })
      }).catch(() => {})
    },
    // 当前页的删除接口
    deleteMethod(deleteIds) {
      return remove(deleteIds)
    },
    getPrintData(data) {
      return list(data)
    }
    // importMethod(files) { // 导入接口
    //   importMethod(files).then(res => {
    //     this.$message({
    //       message: res.msg,
    //       type: 'success'
    //     })
    //     this.getList()
    //   })
    // }
  }
}
</script>

<style lang="less" scoped>
</style>
